package com.cg.w3d1.dao;

import com.cg.w3d1.bean.Employee;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Repository;


import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

@Repository
public class EmployeeDao {
    private static Map<Integer, Employee> employees = null;
    static {
        employees = new HashMap<Integer, Employee>();
        employees.put(0,new Employee(0,"小明",20,"男"));
        employees.put(1,new Employee(1,"小红",19,"女"));
        employees.put(2,new Employee(2,"小智",15,"男"));
        employees.put(3,new Employee(3,"小刚",16,"男"));
        employees.put(4,new Employee(4,"小霞",15,"女"));
    }
    private static Integer initId = 5;

    private void save(Employee employee){
        if (employee.getId() == null){
            employee.setId(initId++);
        }
        employees.put(employee.getId(),employee);
    }
    public Collection<Employee> getAll(){
        return employees.values();
    }
    public Employee getEmpById(Integer id){
        return employees.get(id);
    }
    public void deleteEmp(Integer id){
        employees.remove(id);
    }
}
